package com.Hwadee.staservice.schedule;

import com.Hwadee.staservice.service.StatisticsDailyService;
import com.Hwadee.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService staService;

    // 每隔五秒执行一次
    //@Scheduled(cron = "0/5 * * * * ?")
    public void task1() {
        System.out.println("task1执行了........");
    }

    //在每天凌晨1点执行方法，将前一天数据查询并进行添加
    @Scheduled(cron = "0 0 1 * * ?")//springboot只支持6位
    public void task() {
        staService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
}
